package cn.jia.spring4;

import cn.jia.spring2.pojo.InterfaceImpl.BlankDisc;
import cn.jia.spring2.pojo.myInterface.CompactDisc;
import cn.jia.spring4.annotation.BlankAnnotation;
import cn.jia.spring4.aspect.EncoreableAspect;
import cn.jia.spring4.target.Performance;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

/**
 * Created by jia on 2018/3/27.
 */
@RunWith(SpringJUnit4ClassRunner.class)
/*  @ContextConfiguration会告诉它需要
    在CDPlayerConfig中加载配置。因为CDPlayerConfig类中包含了
    @ComponentScan，因此最终的应用上下文中应该包含CompactDiscbean*/
//@ContextConfiguration(classes = CDConfig.class)
//@ContextConfiguration({"classpath*:spring-context4.xml"})
@ContextConfiguration(classes = {cn.jia.spring4.config.ConcertConfig.class})
public class Test1 {
    @Autowired
    private Performance performance;
    @Resource
    //@Qualifier("blankDisc")
    //使用自定义的限定符,避免注入歧义性
    @BlankAnnotation
    private CompactDisc compactDisc;

    @Test
    public void test1() {
        performance.perform();
        //performance.dump();
        System.out.println();
    }

    @Test
    public void test2() {
        //compactDisc是个代理对象，不能强制类型转换为具体类
      /*  if (compactDisc instanceof BlankDisc) {
            ((BlankDisc) compactDisc).playTrack(0,0);
            System.out.println();
        }*/
        compactDisc.playTrack(0, 0);
        System.out.println();
    }
    @Test
    public void test3(){
        //EncoreableAspect.encoreable.performEncore();
        System.out.println();
    }

}
